import sys
import os
from PySide6.QtWidgets import *
from PySide6.QtGui import *
from PySide6.QtCore import *

class Demo(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.parent = parent
        layout = QVBoxLayout()
        layout.setAlignment(Qt.AlignmentFlag.AlignTop)

        toolbar=QToolBar()        
        
        ck=QCheckBox('NotchesVisible')
        ck.stateChanged.connect(self.OnNotchesVisibleChanged)
        toolbar.addWidget(ck)

        ck=QCheckBox('Wrapping')
        ck.stateChanged.connect(self.OnWrappingChanged)
        toolbar.addWidget(ck)

        ck=QCheckBox('Tracking')
        ck.stateChanged.connect(self.OnTrackingChanged)
        toolbar.addWidget(ck)

        toolbar.addWidget(QLabel('Range:'))
        self.min=QLineEdit()
        toolbar.addWidget(self.min)
        toolbar.addWidget(QLabel('~'))
        self.max=QLineEdit()
        toolbar.addWidget(self.max)
        btn=QPushButton('SetRange')
        btn.clicked.connect(self.SetRange)
        toolbar.addWidget(btn)

        layout.addWidget(toolbar)
        
        self.dial=QDial()
        self.dial.valueChanged.connect(self.OnValueChanged)
        layout.addWidget(self.dial)

        self.setLayout(layout)
    def OnNotchesVisibleChanged(self,state):
        self.dial.setNotchesVisible(state)
        self.parent.OnShowMessage(f"Set NotchesVisible={state}")
    def OnWrappingChanged(self,state):
        self.dial.setWrapping(state)
        self.parent.OnShowMessage(f"Set Wrapping={state}")
    def OnTrackingChanged(self,state):
        self.dial.setTracking(state)
        self.parent.OnShowMessage(f"Set Tracking={state}")
    def SetRange(self):
        min=int(self.min.text())
        max=int(self.max.text())
        self.dial.setRange(min,max)
        self.parent.OnShowMessage(f"Set Range={min}~{max}")
    def OnValueChanged(self,value):
        self.parent.OnShowMessage(f"Current Value={value}")
def runDemo(parent):
    wigdet =  Demo(parent)
    return wigdet